package com.djinfo.work.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Configuration {
	private static final Log log = LogFactory.getLog(Configuration.class);
	
	private Map<String, String> props;
	public static Configuration c = null;

	public Configuration(String configFile) {
		InputStream is = getClass().getResourceAsStream(configFile);
		try {
			this.props = new HashMap<String, String>();
			FileUtil.readToMap(props, is, "utf-8");
			is.close();
		} catch (IOException e) {
			if (log.isErrorEnabled()) {
				log.error("no file: " + configFile + " -->" + e.getMessage(), e);
			}
		}
	}

	public String getProperty(String key) {
		return (String) this.props.get(key);
	}

	public static Configuration getInstance() {
		if (c == null) {
			c = new Configuration("/config.properties");
		}

		return c;
	}
}